package frontend.parser.node.decl;

import frontend.lexer.token.Token;
import frontend.parser.node.*;
import frontend.parser.node.stmt.Block;

import java.util.ArrayList;

public class FuncDef extends Node {
    // 函数定义    FuncDef → FuncType Ident '(' [FuncFParams] ')' Block // b g j
    private boolean returned;
    private TokenNode identTokenNode;
    private boolean hasFuncFParams = false;
    private FuncFParams funcFParams; // 可以为null
    private Block block;

    private ArrayList<FuncFParam> funcFParamList = new ArrayList<>();
    public Block getBlock() {
        return block;
    }

    public void addFuncType(FuncType funcType) {
        super.add(funcType);
        returned = funcType.isReturned();
    }
    public void addIdentTokenNode(TokenNode identTokenNode) {
        super.add(identTokenNode);
        this.identTokenNode = identTokenNode;
    }
    public void addFuncFParams(FuncFParams funcFParams) {
        super.add(funcFParams);
        this.hasFuncFParams = true;
        this.funcFParams = funcFParams;
        this.funcFParamList = funcFParams.getFuncFParamList();
    }
    public void addBlock(Block block) {
        this.block = block;
    }

    public boolean isReturned() {
        return returned;
    }

    public TokenNode getIdentTokenNode() {
        return identTokenNode;
    }

    public boolean hasFuncFParams() {
        return hasFuncFParams;
    }

    public ArrayList<FuncFParam> getFuncFParamList() {
        return funcFParamList;
    }

    public String getIdentName() {
        return identTokenNode.getContent();
    }

    public Token getIdentToken() {
        return identTokenNode.getToken();
    }

    // symbol manager
//    private FuncSymbol funcSymbol;
////    private ArrayList<ParaSymbol> paraSymbolList = new ArrayList<>();
//    public FuncSymbol toFuncSymbol() {
////        if (hasFuncFParams) {
////            funcFParamList.forEach(funcFParam -> this.paraSymbolList.add(funcFParam.toParaSymbol()));
////        }
//        return (this.funcSymbol =
//                new FuncSymbol(identTokenNode, returned));
//    }
//
//    public FuncSymbol getFuncSymbol() {
//        return funcSymbol;
//    }

//    public ArrayList<ParaSymbol> getParaSymbolList() {
//        return paraSymbolList;
//    }
}
